package com.mew.common.rest.mail;

import com.mew.common.entity.mail.Accessory;
import com.mew.common.util.DateUtils;
import com.zebra.common.ZebraBaseMessage;
import io.netty.buffer.ByteBuf;
import lombok.*;

import java.util.Date;
import java.util.List;

/**
 * 邮件详情
 */
@Data
@ToString
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class MailDetailInfoResponseMessage extends ZebraBaseMessage<MailDetailInfoResponseMessage> {
    private Integer id; //ID
    private Integer type;//类型
    private String title; //标题
    private String content; //内容
    private Long sendUserId;//发送人ID
    private Long receiveUserId;//接收人ID
    private Date sendTime; //发送时间
    private Date receiveTime;//领取时间
    private Integer status;//状态
    private int res;//自定义状态用
    private List<Accessory> accessories; //附件列表

    @Override
    public void write(ByteBuf b) {
        writeInt(b,id);
        writeInt(b,type);
        writeString(b,title);
        writeString(b,content);
        writeLong(b,sendUserId == null? -1 : sendUserId);
        writeLong(b,receiveUserId);
        writeString(b, DateUtils.format(sendTime,"yyyy.MM.dd HH:mm:ss"));
        writeString(b, DateUtils.format(receiveTime,"yyyy.MM.dd HH:mm:ss"));
        writeInt(b,status);
        writeInt(b,res);
        writeInt(b,accessories == null? 0:accessories.size());
        if(accessories != null){
            for (Accessory accessory : accessories) {
                accessory.write(b);
            }
        }
    }

    @Override
    public MailDetailInfoResponseMessage read(ByteBuf byteBuf) {
        return null;
    }
}
